--[[
Ref: https://github.com/tuanpmt/lua-async
Example:

async.waterfall({
    function (callback)
        callback(nil, "one", "two");
    end,
    function (callback, arg1, arg2)
        --arg1 now equals "one" and arg2 now equals "two"
        print(arg1, arg2)
        callback(nil, "three");
    end,
    function(callback, arg1)
        --arg1 now equals "three"
        print(arg1)
        callback(nil, "done");
    end
}, function (err, result)
   -- result now equals "done"
   print(result)
end);

]]

local M = {}

function M.waterfall(tasks, cb)
	local nextArg = {}
	for i, v in pairs(tasks) do
		local error = false
		v(function(err, ...)
			local arg = {...}
		    nextArg = arg;
		    if err then
				error = true
			end
		end, unpack(nextArg))
		if error then return cb("error") end
	end
	cb(nil, unpack(nextArg))
end

function M.eachSeries(arr, iterator, callback)
	
end
return M